#include "Player.h"

Player::Player(){
	shoot = false;
	m_shootingMode = 1;
	m_lives = 5;
	currShot = 0;
	prevShot = 0;
	betShot = 0;
	shootSpeed = 100;
};
Player::~Player(){};

void Player::update() {
	m_pInput = Input::getInstance();

	m_PhysicObject.m_velocity.set(0.0f, 0.0f);
	if(m_pInput->keyDown(DIK_W)){
		m_PhysicObject.m_velocity.add(Vector2D(0.0f, -1.0f));
	}
	if(m_pInput->keyDown(DIK_A)){
		m_PhysicObject.m_velocity.add(Vector2D(-1.0f, 0.0f));
	}
	if(m_pInput->keyDown(DIK_S)){
		m_PhysicObject.m_velocity.add(Vector2D(0.0f, 1.0f));
	}
	if(m_pInput->keyDown(DIK_D)){
		m_PhysicObject.m_velocity.add(Vector2D(1.0f, 0.0f));
	}

	//Shooting cooldown
	currShot = clock();
	betShot = currShot - prevShot;
	if(betShot >= shootSpeed) {
		//set shoot to true
		if(m_pInput->keyDown(DIK_SPACE)) {
			shoot = true;
		}
		prevShot = currShot;
	}
	//Change shoot mode
	if(m_pInput->keyPressed(DIK_Q)) { 
		m_shootingMode++;
		if(m_shootingMode > 2) {
			m_shootingMode = 1;
		}
	}
	m_PhysicObject.m_velocity.normalize();
	m_PhysicObject.m_velocity.multiply(m_speed);
	
	
}
void Player::render() {
	Entity::render();

	for(int i = 0; i < m_BulletList.Get_Size(); i++){
		m_BulletList.Get_Data(i)->Draw();
	}
}
void Player::release(){
	Entity::release();

	for(int i = 0; i < m_BulletList.Get_Size(); i++){
		m_BulletList.Get_Data(i)->Release();
	}
	m_BulletList.Clear();

	m_pInput = 0;
}
void Player::setLives(int value) {
	m_lives = value;
}
int Player::getLives() {
	return m_lives;
}